1. Introduction
2. Requirements
3. Menu Buttons
4. Tutorial
5. Conditionals
6. Conclusion
This document will explain how to build AI’sAIs for ships,
bases and other objects in Bridge Commander. You will find the editor works to
build AI’sAIs much like building a flow chart, allowing
you to set different priorities and depending on the situation.
You will need the Python interpreter installed on your computer. It can be obtained in a variety of ways, including at www.python.org. You will also need Python MegaWidgets: see pmw.sourceforge.net. During development, we used Python version 1.52, and PMW version 0.8.4.
Here is a quick explanation of the options you have available from the menus.
File – Here you can Load, Save and Quit, which are all self-explanatory. “Clear All” will clear the editor’s main window. Warning: you will not be prompted to save you work when clearing, quitting or loading a new AI, so be sure to save often.
Create AI – This is the most important function of the editor. Here you can add a variety of AI components to your AI. These will be explained in more detail later, but here is a quick run down
· Conditional – Use this to check the environment around the AI. Such as: what other ships are in the same set, how much damage has been taken, etc. This AI will link to another one, and when the condition is met it will activate (or deactivate) the AI component it is attached to.
· Scripted (plain) – This AI component will tell the ship with the AI to do something, such as: stay in place, circle another object, flee from an object, etc.
·
Preprocessing – Um,…Preprocessing AI’sAIs are special scripts
that run in addition to the AI’sAIs they contain. An example is the weapon firing preprocess:
whenever AI contained by the firing preprocess is running, the ship will try to fire its weapons.
·
Priority list – As its name suggests, use this AI component to set the
priorities of other AI components.
·
Sequence – As its name suggests, use this to have other AI
components happen in order.
·
Random – As its name suggests, use this to have other AI
components occur in a random order.
·
Compound – Um,…These are just AI files that have been saved
elsewhere. If you create an AI and you
want to use that AI within another, larger AI, then you can insert it as a
Compound AI.
·
Special – These are common but specialized AI components that have
been pre-built for your convenience. The most common is the Avoid Obstacles
Preprocess, which will keep your ship from hitting other objects in the set.
Advanced –
·
Edit Pre-AI Save Text – Um,…AI files are just scripts. This allows you to edit the beginning of the
script. This is useful if you want to
pass additional arguments to an AI file’s Create() function.
·
AI Distriubiutes
Building - Um,…An extremely painful
feature that should probably be avoided.
=) It=) It requires some hand-processinghand processing of the AI file to work
properly. If it’s enabled, the game
will take a little longer to create your AI, distributing its work across
several frames, so that it doesn’t hitch the framerateframe rate too badly on any one
frame.
·
Advanced Features - Um,…Enables Scripted AI’s that should normally not be available,available, unimplemented
features in some of the Compound AI’s, and the “Edit Post-AI Save
Text” button in AI configuration. Advanced Features should normally be Off
(not checked).
4.0
Tutorial
So, how the heck do you make an AI? This little tutorial
will teach you how to make a basic combat AI:
Open the AI editor by double clicking the AIEditor.py file. Open the “Create AI” menu and select “(compound)”. You will notice a white box with a purple outline appear in the editor’s main window (it says “compound”). You can hold left click on this box and move it around the main window. Right click on this box.
Right clicking on this box will give you more detail about the AI component and allow you to modify it. You can rename this component at the top of the detail window by typing over the word “compound”. Rename this AI component “ChickenKiller” (each component must have it’s own name, and we may have more AI components named “compound”).
Press the “select file” button, then select “BasicAttack.py”. You will see the detail window change, as this component is now a basic attack AI component. You will see options such as Difficulty, MaxFiringRange, UseCloaking and others.
Next you will have to name the target for this AI. In the window next to the words “Function Arguments”, type the following:
pShip, “Chicken”
Click “OK” at the bottom of the detail window to return to the main window. This AI will now cause the ship it is assigned to attack any ship named Chicken.
Good. But when you put this AI in the game you notice your ChickenKiller ship seems to enjoy flying into the star base and planets. No problem. Open the “Create AI” menu again and open the “special” sub-menu, and select “Avoid Obstacles Preprocess”. An AI Component with a green border will appear in the main window (right click to re-name it). It may cover your “ChickenKiller” component, if so left click it and drag it to move it away. You will notice a little hat on the top of this component. Right click on this hat and drag to draw a line to the “ChickenKiller” component. Your AI will now make a point of avoiding collisions before attacking Chicken.
Great, but what if you want more than one enemy to attack? Simple. One option is to just add the next target to your basic attack. i.e.:
pShip, “Chicken 1”, “Chicken 2”
You can also set the priority or order Chicken 1 and Chicken 2 are attacked. Let’s try priority.
Select “Create AI”, and then choose “Priority List”. You
will se a Yellow box with a line to a small box with a “1” in it. Right click
to re-name this component and change the number of AI’sAIs to 2, then
press “OK”. There should now be two small boxes, “1” and “2”. Connect the hat
on your “Avoid Obstacles” to the “PriorityList” component by right clicking and
dragging, just as you did before. You can now Right click and drag from the
small box called “1” to your Basic Attack component. Next, right click on the
Basic Attack component and press the “copy” button. This will create a second
Attack AI component called “ChickenKiller_2”. Right-click on this new
component, change the target name from “Chicken” to “Chicken 2” and press “OK”.
Attach the small “2” box to this new Attack AI component.
Bingo. Now your ship will attack “Chicken” if it can, and then it will attack “Chicken 2”. Follow exactly the same steps for Sequence or Random.
5.0 Conditionals
A major AI component
not covered in the above tutorial is the conditional. A conditional is
used to check the surroundings or situation of the ship(s) assigned your AI. You could use a
conditional component
to do
things such
as: check what other
ships are in the same set, check what set your ship is in, check how much
damage the ship has taken,
check who
is attacking the ship or who the ship is attacking, what is in a set
range of the ship, etc.
Let’s take our sample
AI from the tutorial and add a condition to it. As it stands the
ship assigned the sample AI will attack “Chicken” as it’s top priority, and
“Chicken 2” as it’s next target. Lets add a conditional to check the range of “Chicken”
to the ship, and if it is too far away we will target “Chicken 2”
Add a conditional by
selecting “Conditional” from the “Create
AI” menu. A box with a red border will appear. Connect the small “1” box to this
conditional, then connect the conditional to the “ChickenKiller” attack component
(as described in the tutorial, right click and drag from the “small “1” box to
the conditional component, then right click and drag from the conditional’s hat to the attack
AI). Now right click on the conditional and re-name it in the detail window.
Find the button “Add Conditional,”
and click it. This will open a new window where you will see a variety
of potential conditions you can check. Find the one called “ConditionInRange”
and click its radio button. At the top of this window you can name this
condition, name it “IsChickenInRange”. At the bottom you can specify
the parameters, in this case distance and object. Type the following in the
parameters:
240, “Chicken”
Note: 240 is in “game units”, which translates to
approx 42km (1km = 5.71428
game units)
Good, now press “OK”.
You will see IsChickenInRange listed as a condition in the detail window of the
conditional component. Now, in the “def” window (the big white window)
add the following:
if(bIsChickenInRange):
return ACTIVE
return DORMANT
Note: the second line
has a tab in front of the word “return”.
So, what does this
mean? It means: if “Chicken” within 240gm of the ship assigned this AI, this conditional
will be “active”, or it will pass on to the attack AI component after the
conditional, and thus the ship will attack Chicken. If the ship is further than
240gm it the conditional will become “dormant” so the AI will go to the next item on the
priority list, thus attacking “Chicken 2”.
Please look at the
AIs included as samples for other uses of the conditional component.
6.0 Conclusion
This document could
be 200 pages long and still not cover everything the AI editor can do. Therefore we have
included all AI’sAIs that were made for the game. Please look closely at these AI’sAIs for more examples of
how to make AI
for Bridge Commander.